"""
Case Type   : 小型化
Case Name   : HTAP行列融合特性--不支持系统表，合理报错
Create At   : 2024/11/12
Owner       : ningyali
Description :
    1.查询系统表
    2.对系统表进行全表转换
Expect      :
    1.执行成功
    2.合理报错
History     :
"""

import os
import unittest

from testcase.utils.Logger import Logger
from testcase.utils.CommonSH import CommonSH


class HTAP(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        self.pri_sh = CommonSH('PrimaryDbUser')

    def test_trans(self):
        text = '----step1:查询系统表;expect:执行成功----'
        self.log.info(text)
        sql = f"select schemaname, tablename from pg_tables " \
              f"where schemaname='pg_catalog'"
        q_res = self.pri_sh.execut_db_sql(sql)
        self.log.info(q_res)

        text = '----step2:对系统表进行全表转换;expect:合理报错----'
        self.log.info(text)
        for line in q_res.splitlines()[2:-1]:
            schema = line.strip().split('|')[0].strip()
            t_name = line.strip().split('|')[1].strip()
            sql = f'alter table {schema}.{t_name} imcstored;'
            alter_res = self.pri_sh.execut_db_sql(sql)
            self.log.info(alter_res)
            self.assertIn('ERROR:  permission denied', alter_res, f'执行失败:{text}')

    def tearDown(self):
        self.log.info(f'-----{os.path.basename(__file__)} end-----')
